package com.example.calender

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

// 定义 NoteAdapter 类
class NoteAdapter(private val context: Context, public val notes: List<Note>) : RecyclerView.Adapter<NoteAdapter.NoteViewHolder>() {

    // 创建 ViewHolder 类
    inner class NoteViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val titleTextView: TextView = itemView.findViewById(R.id.titleTextView)
        val descriptionTextView: TextView = itemView.findViewById(R.id.descriptionTextView)
    }

    // 创建新视图并返回 ViewHolder 实例
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NoteViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_note, parent, false)
        return NoteViewHolder(view)
    }

    // 绑定数据到视图上
    override fun onBindViewHolder(holder: NoteViewHolder, position: Int) {
        val note = notes[position]
        holder.titleTextView.text = note.title
        holder.descriptionTextView.text = note.description
    }

    // 返回数据项的数量
    override fun getItemCount(): Int = notes.size


}